﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Administration;
using System.Windows;
using System.Windows.Controls;

namespace SharePointCommander.Model.TreeView
{
    public class SCServiceInstanceDependencyCollection : SCTreeViewItem<SPServiceInstanceDependencyCollection>
    {
        public SCServiceInstanceDependencyCollection(SCTreeViewItem parent, SPServiceInstanceDependencyCollection serviceInstances)
            : base(parent, serviceInstances)
        {
            this.Header = "Service Instances";
            IsExpanded = false;
            Expanded += new RoutedEventHandler(SCServiceInstanceCollection_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCServiceInstanceCollection_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (item.ItemsSource.Cast<object>().Contains(null))
            {
                item.ItemsSource = from s in SPObject select new SCServiceInstance(this, s);
            }
        }
    }
}
